﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;

namespace ConfExpert.Forms.Depo._7C
{
    public partial class EskiYeniKod : XForm
    {
        string tip;
        int CustomerId;
        public EskiYeniKod(string _tip, int CustomerId)
        {
            InitializeComponent();
            tip = _tip;
            this.Text = tip;
            this.CustomerId = CustomerId;
        }

        private void EskiYeniKod_Load(object sender, EventArgs e)
        {

            gridView1.Init("GetKodListesi", tip, CustomerId);

            switch (tip)
            {
                case "GpBedenGarni":
                    gridView1.SetCaptions("ProductId:AnaBedenId");
                    gridView1.Columns["GarniId"].ColumnEdit = RI(Rp.V_Kumas);
                    gridView1.MakeColumnInvisible("Arts");
                    gridView1.MakeReadOnly("ProductId", "GarniId");
                    gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
                    break;

                //case "Muadil":
                //    gridView1.DataTable().TableNewRow += EskiYeniKod_TableNewRow;
                //    gridView1.Columns["AlternatifId"].ColumnEdit = RI(Rp.V_Kumas);
                //    gridView1.MakeColumnInvisible("Tarih", "MuadilId", "CustomerId");
                //    gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
                //    break;

                //case "YeniKodlar":
                //    gridView1.MakeColumnInvisible("ProductId", "YId", "EId");

                //    GridColumn colPhoto = gridView1.Columns["EScan"];
                //    colPhoto.ColumnEdit = new RepositoryItemPictureEdit();
                //    (colPhoto.ColumnEdit as RepositoryItemPictureEdit).SizeMode = PictureSizeMode.Clip;
                //    (colPhoto.ColumnEdit as RepositoryItemPictureEdit).NullText = " ";
                //    CenterGridColumn(colPhoto);
                //    break;

            }
            gridView1.AddSummary();
            gridView1.BestFitColumns();

            btn.ItemClick += btn_ItemClick;
        }

        void EskiYeniKod_TableNewRow(object sender, System.Data.DataTableNewRowEventArgs e)
        {
            e.Row["CustomerId"] = CustomerId;
        }

        void btn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            gridView1.Update("", tip);

            if (tip == "GpBedenGarni")
                gridView1.RefreshDataSource(true, "UpdGpBedenGarni");
            gridView1.BestFitColumns();
        }

    }
}
